$def with (get_results)

$ q = query_param('q', '').strip()
$ results_per_page = 100
$ page = query_param('page')
$if page:
    $ page = int(page)
$else:
    $ page = 1
$ offset = (page - 1) * results_per_page

$var title: $_('Search Open Library for "%(query)s"', query=q)
$ sort = query_param('sort', None)

<div id="contentHead">
    <h1>$_("Search Authors")</h1>
</div>

<div id="contentBody">
  $:macros.SearchNavigation()

  <div class="section">
    <form class="siteSearch olform" action="">
        $:render_template("search/searchbox", q=q)
    </form>
  </div>

    $ results = get_results(q, offset=offset, limit=results_per_page, sort=sort)

    $if q and results.error:
        <strong>
            $for line in results.error.splitlines():
                $line
                $if not loop.last:
                    <br>
        </strong>

    $if q and not results.error:
        $if results.num_found:
            <div class="search-results-stats">$ungettext('%(count)s hit', '%(count)s hits', results.num_found, count=commify(results.num_found))
              $if results.num_found > 1:
                $:render_template("search/sort_options.html", selected_sort=sort, search_scheme="authors")
              $ user_can_merge = ctx.user and ("merge-authors" in ctx.features or ctx.user.is_admin())
              $if results.num_found >= 2 and user_can_merge:
                $ keys = ','.join(doc['key'].split("/")[-1] for doc in results.docs)
                <div class="mergeThis">$_('Is the same author listed twice?') <a class="large sansserif" href="/authors/merge?records=$keys">$_('Merge authors')</a></div>
            </div>
        $else:
            <center>
                <div class="red">$:_('No <strong>authors</strong> directly matched your search')</div>
                <hr>
              </center>
              <div id="fulltext-search-suggestion" data-query="$q">
                  $:macros.LoadingIndicator(_("Checking Search Inside matches"))
              </div>
       $if results.num_found:
        <ul class="authorList list-books">
        $for doc in results.docs:
            $ n = doc['name']
            $ num = doc['work_count']
            $ wc = ungettext("%(count)d book", "%(count)d books", num, count=num)
            $ date = ''
            $if 'birth_date' in doc or 'death_date' in doc:
                $ date = doc.get('birth_date', '') + ' - ' + doc.get('death_date', '')
            $elif 'date' in doc:
                $ date = doc['date']
            <li class="searchResultItem">
	      <img src="$get_coverstore_public_url()/a/olid/$(doc['key'].split('/')[-1])-M.jpg" itemprop="image" class="cover author" alt="$_('Photo of %(author)s', author=n)">
	      <div class="details">
		<a href="$doc['key']" class="larger">$n</a>&nbsp;<span class="brown small">$date</span><br />
		<span class="small grey"><b>$wc</b>
                $if 'top_subjects' in doc:
                  $_('about %(subjects)s', subjects=', '.join(doc['top_subjects'])),
                $:_('including <i>%(topwork)s</i>', topwork=doc.get('top_work', ''))</span>
	      </div>
            </li>
        </ul>

        $:macros.Pager(page, results.num_found, results_per_page)
  </div>

</div>
